<template>
	<om-formsub-outer :index="index">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {subOnLoad, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return {
				initValue:{
				},
				autoformdata: [],
				cachename:'',
				index:null,
				datas:[],
				order:0,
				formdata:{},
				studyDirectCacheKey:"hr-u-confirm-data-info-eduOrSchool-studydirect-cache"
			}
		},
		methods: {
			verifyStudyDirectE(){
				let _that = this
				if(!_that.$refs.autoform.formdata.eduECode){
					let title = _that.$refs.autoform.getEditorTitle("eduOrSchool",'eduECode')
					_that.om.toast('请先选择'+ title)
					return false
				}else{
					return true
				}
			},
			onSelectEdu(item){
				let _that = this
				_that.$refs.autoform.changeEditor("eduOrSchool", "studyDirectEName", {
						"type": "editlinkbox",
						"prompt": "请选择",
						"linkParam":{
							other: JSON.stringify({
								eduCode:item.code
							}),
							namefield:"dicname",
							initload:true,
							searchByBackground:true,
							searchfield:'q',
							url:"major/getMajorList",
							cachename:_that.studyDirectCacheKey
						}
					})
					_that.$refs.autoform.changeEditor("eduOrSchool","eduECode","verify","verifyStudyDirectE")
			},
			clearEdu(){
				let _that = this
				_that.$refs.autoform.clear("eduOrSchool", "eduECode")
				_that.$refs.autoform.clear("eduOrSchool", "studyDirectEId")
			},
			initLoad(){
				let _that = this
				changeEditor(_that.autoformdata[0].editors, "startDateE","endField","endDateE")
				changeEditor(_that.autoformdata[0].editors, "endDateE","startField","startDateE")	
				//学历
				var pro1 = _that.om.request('dictZero/getCombobox',{code:"23868"})
				//学习形式
				var pro2 = _that.om.request('dictZero/getCombobox',{code:"34783"})
				//学业结束类型
				var pro3 = _that.om.request('tsysdict/getListByCode',{code:"38651"})
				//学制
				var pro4 = _that.om.request('tsysdict/getListByCode',{code:'38655'})
				//学位
				var pro5 = _that.om.request('tsysdict/getListByCode',{code:'38666'})
				Promise.all([pro1, pro2,pro3,pro4,pro5]).then(res=>{
					_that.$refs.autoform.changeEditor("eduOrSchool", "eduECode", "data", configSelectData(res[0], "code", "dicname"))
					_that.$refs.autoform.initSelectIndex("eduOrSchool", "eduECode")
					_that.$refs.autoform.changeEditor("eduOrSchool", "studyWayCode", "data", configSelectData(res[1], "code", "dicname"))
					_that.$refs.autoform.initSelectIndex("eduOrSchool", "studyWayCode")
					_that.$refs.autoform.changeEditor("eduOrSchool","learningEndTypeId",'data',configSelectData(res[2],'id','dicname'))
					_that.$refs.autoform.initSelectIndex("eduOrSchool","learningEndTypeId")
					_that.$refs.autoform.changeEditor("eduOrSchool","learningLengthTypeId",'data',configSelectData(res[3],'id','dicname'))
					_that.$refs.autoform.initSelectIndex("eduOrSchool","learningLengthTypeId")
					_that.$refs.autoform.changeEditor("eduOrSchool","degreeId",'data',configSelectData(res[4],'id','dicname'))
					_that.$refs.autoform.initSelectIndex("eduOrSchool","degreeId")
				})
			}
		},
		onLoad(e){
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								_that.initLoad()
							}
						}
					});
					_that.$nextTick(function(){
						if(_that.$refs.autoform.formdata.eduECode){
							_that.onSelectEdu({code:_that.$refs.autoform.formdata.eduECode})
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if(_that.$refs.autoform){
				uni.getStorage({
					key: this.studyDirectCacheKey,
					success: function(res) {
						if(res.data){
							let d = res.data
							var formdata  = _that.$refs.autoform.formdata
							if(Object.prototype.toString.call(d) != "[object Object]"){
								formdata.studyDirectEName = d
							}else{
								formdata.studyDirectEId = d.id
								formdata.studyDirectEName = d.dicname
							}
							uni.removeStorage({
								key: _that.studyDirectCacheKey
							});
						}
					}
				});
			}
		}
	}
</script>

<style>
</style>
